package io.scnb.lesson001.demo2;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;

public class Client {

    public static void main(String[] args) {
        String beanXml = "classpath:/io/scnb/lesson001/demo2/beans_alias.xml";

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);

        for (String beanName : Arrays.asList("user1", "user2", "user3", "user4", "user5")) {
            // 获取bean的别名
            // getAliases通过bean的名称获取这个bean的所有别名
            String[] alias = context.getAliases(beanName);
            System.out.println(String.format("beanName:%s, 别名:[%s]", beanName, String.join(", ", alias)));
        }

        System.out.println("spring容器中所有bean如下：");
        // getBeanDefinitionNames用于获取容器中所有bean的名称
        for (String beanName: context.getBeanDefinitionNames()) {
            // 获取bean的别名
            String[] aliases = context.getAliases(beanName);
            System.out.println(String.format("beanName:%s, 别名:[%s]", beanName, String.join(", ", aliases)));
        }
    }
}
